import wh.ispct.Content
import wh.ispct.LinkContent
import wh.ispct.Menu
import wh.ispct.PageConfig
import wh.ispct.User


class BootStrap {

	def init = { servletContext -> initMenu() }

	def initMenu(){
		if(User.findAll().size() == 0){
			//系统用户
			User admin = new User(loginId:"admin",name:"系统管理员",organ:"市局督察支队").save()
			
			//固定区域的文本内容
			Menu m0 = new Menu(name:"固定内容",type:"system",singleContent:true,sort:0,visible:false).save()
			Menu m01 = new Menu(name:"今日值班",type:"content",singleContent:true,sort:1,visible:false,parentMenu:m0).save()
			Content c01 = new Content(title:"今日值班",text:"<label style='width: 80px; font-weight: bolder;'> 今日值班: </label> <span id='duty'>张支队</span> <label style='width: 80px; font-weight: bolder;'> 联系电话: </label> <span id='duty'>13805532716</span><label style='width: 80px; font-weight: bolder;'> 固定电话: </label> <span id='duty'>0553-8888888</span>",source:'系统初始化',author:'系统后台',menu:m01).save()
			Menu m02 = new Menu(name:"今日天气",type:"content",singleContent:true,sort:2,visible:false,parentMenu:m0).save()
			Content c02 = new Content(title:"今日天气",text:"<label style='width: 80px; font-weight: bolder;'> 今日天气: </label> <span>多云 20～32度 北风 3～5级</span>",source:'系统初始化',author:'系统后台',menu:m02).save()
			
			Menu m03 = new Menu(name:"公告栏",type:"content",sort:3,visible:false,parentMenu:m0).save()
			Menu m05 = new Menu(name:"月度值班表",type:"content",sort:4,visible:false,parentMenu:m0).save()
			Menu m06 = new Menu(name:"系统弹窗",type:"content",sort:5,visible:false,parentMenu:m0).save()
			
			//部门介绍
			Menu m1 = new Menu(name:"部门介绍",type:"content",sort:1).save()
			
			Menu m1_1= new Menu(name:"队伍简介",type:"content",singleContent:true,sort:1,parentMenu:m1).save()

			Menu m1_2= new Menu(name:"督察职责",type:"content",singleContent:true,sort:2,parentMenu:m1).save()

			Menu m1_3= new Menu(name:"机构设置",type:"content",singleContent:true,sort:3,parentMenu:m1).save()

			Menu m1_4= new Menu(name:"联系方式",type:"content",singleContent:true,sort:4,parentMenu:m1).save()
			Menu m1_5= new Menu(name:"通讯录",type:"content",singleContent:true,sort:5,parentMenu:m1).save()
			
	       
			//主页新闻
			Menu m3= new Menu(name:"支队新闻",type:"content",sort:3,parentMenu:null).save()
	
			Menu m4= new Menu(name:"通知通报",type:"content",sort:4,parentMenu:null).save()
			
			Menu m5= new Menu(name:"上级文件",type:"content",sort:5,parentMenu:null).save()
			
			Menu m6= new Menu(name:"支队动态",type:"content",sort:6,visible:false,parentMenu:null).save()
	
			Menu m7= new Menu(name:"督察提示",type:"content",sort:7,parentMenu:null).save()
			
			Menu m8= new Menu(name:"绩效考评",type:"content",sort:9,parentMenu:null).save()
			
			Menu m9= new Menu(name:"投诉维权",type:"content",sort:8,visible:false,parentMenu:null).save()
	
			Menu m10= new Menu(name:"专项行动",type:"content",sort:10,parentMenu:null).save()
	
			Menu m11= new Menu(name:"法律法规",type:"content",sort:11,parentMenu:null).save()
			
			Menu m12= new Menu(name:"学习园地",type:"content",sort:12,visible:false,parentMenu:null).save()
			
			
			//主页系统链接类
			Menu m2 = new Menu(name:"主页超链接",type:"system",sort:1,visible:false).save()
			
			Menu m21 = new Menu(name:"督察导航",type:"system",sort:1,parentMenu:m2).save()
			Menu m211= new Menu(name:"市内督察",type:"link",sort:1,parentMenu:m21).save()
			["镜湖区分队","弋江区分队","鸠江区分队","开发区分队","三山区分队"].eachWithIndex() { it,i ->
				new LinkContent(linkText: it,linkUrl:"#", author:admin.name ,sort:i,menu:m211 ).save()
			}
			
			Menu m212 = new Menu(name:"省内督察",type:"link",sort:2,parentMenu:m21).save()
			["合肥","马鞍山","蚌埠","阜阳"].eachWithIndex() { it,i ->
				new LinkContent(linkText: it,linkUrl:"#", author:admin.name ,sort:i,menu:m212 ).save()
			}
			
			Menu m213 = new Menu(name:"全国督察",type:"link",sort:3,parentMenu:m21).save()
			["北京","上海"].eachWithIndex() { it,i ->
				new LinkContent(linkText: it,linkUrl:"#", author:admin.name ,sort:i,menu:m213 ).save()
			}
			
			Menu m22= new Menu(name:"市局首页",type:"link",singleContent:true,sort:2,parentMenu:m2).save()
			new LinkContent(linkText: m22.name,linkUrl:"#", author:admin.name ,sort:1,menu:m22 ).save()
			
			Menu m23= new Menu(name:"旧版主页",type:"link",singleContent:true,sort:3,parentMenu:m2).save()
			new LinkContent(linkText: m23.name,linkUrl:"#", author:admin.name ,sort:1,menu:m23 ).save()
			
			Menu m24 = new Menu(name:"应用系统",type:"link",sort:4,parentMenu:m2).save()
			["户籍系统","PGIS系统","派基3.0"].eachWithIndex() { it,i ->
				new LinkContent(linkText: it,linkUrl:"#", author:admin.name ,sort:i,menu:m24 ).save()
			}
			
			//主页配置
			PageConfig pageCfg = new PageConfig(page:"index",
				menu11:m4,menu12:m5,
				menu21:m7,menu22:m8,
				menu31:m10,menu32:m11,
				menu41:m12).save()
		}
		
		Menu navigation = Menu.findByName("督察导航")
		if(navigation!=null && Menu.findByName("公安部省厅") == null){
				Menu nav25 = new Menu(name:"公安部省厅",type:"link",sort:5,parentMenu:navigation).save()
				["公安部","安徽省公安厅"].eachWithIndex() { it,i ->
					new LinkContent(linkText: it,linkUrl:"#", author:"系统管理员" ,sort:i,menu:nav25 ).save()
				}
				
				new Menu(name:"全国导航",type:"link",sort:6,parentMenu:navigation).save()
				new Menu(name:"省内导航",type:"link",sort:7,parentMenu:navigation).save()
				
				new Menu(name:"市局机关",type:"link",sort:8,parentMenu:navigation).save()
				new Menu(name:"县分局支队",type:"link",sort:9,parentMenu:navigation).save()
		}
		
	}

	def destroy = {
	}
}
